package servlet.cookie;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class getCookieServlet
 */
public class GetCookieServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		//클라이언트로 부터 받은 쿠키값들 조회해서 출력
		//쿠키 값들 조회
		Cookie [] cs = request.getCookies();
		out.println("<html><body>");
		if(cs!=null){
			for(int i = 0; i<cs.length; i++){
				String name = cs[i].getName(); //Cookie
				String value = cs[i].getValue();
				out.println(name + "----" + value + "<br>");
			}
		}else{
			out.println("전송된 쿠키 값이 없습니다.");
		}
		out.println();
		out.println("</body></html>");
	}

}
